package ru.maksb.exchange.utils;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.concurrent.BlockingQueue;

public class MessageSender implements Runnable {
	private BlockingQueue<String> messages;
	private ObjectOutputStream out;
	
	public MessageSender(BlockingQueue<String> messages, ObjectOutputStream out) {
		this.messages = messages;
		this.out = out;
	}

	public void run() {
		try {
			while (true) {
				String message = messages.take();
				out.writeObject(message);
				out.flush();
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
